//
//  RooteViewController.swift
//  阿酷微博
//
//  Created by co on 16/3/12.
//  Copyright © 2016年 王南侠. All rights reserved.
//

import UIKit
import HMRefresh

class RooteViewController: UIViewController {
    
    // MARK: - 公共属性
    // 用户登录标记
    var userLogin = false
    lazy var tableView = UITableView(frame: CGRectZero, style: .Plain)
    lazy var refreshControllor = HMRefreshControl()

    /// 访客视图属性
    var visitorView:VisitorView?
    
    
    // MARK: - 视图声明周期
    override func loadView() {
        
        userLogin ? setupTableView() : setupvistorView()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadData()
    }
    
    
    /// 接受内存警告
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    
    }
    

    /// 加载数据
    func loadData(){
        
        
    }

}

// MARK: - VisitorViewDelegate
extension RooteViewController:VisitorViewDelegate{
    func visitorViewDidRegister() {
        print("注册-导航栏")
    }
    
    func visitorViewDidLogin() {
        let outhVc = OAuthViewController()
        let nav = UINavigationController(rootViewController: outhVc)

        presentViewController(nav, animated: true, completion: nil)
        print("登录-导航栏")
    }
    
}

// MARK: - 设置界面
extension RooteViewController {
    
    /// 设置访客视图
    private func setupvistorView(){
        
        visitorView = VisitorView()
        
        // 设置代理
        visitorView?.delegate = self
        
        view = visitorView
        
        // 设置状态栏按钮 - 如果换行参数，一定要保证一个参数一行
        navigationItem.leftBarButtonItem = UIBarButtonItem(
            title: "注册",
            style: .Plain,
            target: self,
            action: "visitorViewDidRegister"
        )
        navigationItem.rightBarButtonItem = UIBarButtonItem(
            title: "登录",
            style: .Plain,
            target: self,
            action: "visitorViewDidLogin")
        
    }
    
    /// 表格视图
    private func setupTableView() {
        view = tableView
        
        tableView.dataSource = self
        tableView.delegate = self
    }
    
/// 刷新控件
    // 需要刷新控件的子控制器单独调用
    func setupRefreshControl(){
        
        tableView.addSubview(refreshControllor)
        
        // 设置下拉刷新视图
        refreshControllor.pulldownView = CZPulldownRefreshView.refreshView()
        refreshControllor.normalString = "下拉起飞"
        refreshControllor.pullingString = "放开起飞"
        refreshControllor.refreshingString = "正在起飞"
        refreshControllor.lastRefreshString = "末次"
        
        refreshControllor.addTarget(self, action: "loadData", forControlEvents: .ValueChanged)
        

    }
}


extension RooteViewController:UITableViewDataSource,UITableViewDelegate{
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
    
}

